<% layout('/layouts/default.html', {title: '文件销毁任务管理', libs: ['dataGrid']}){ %>
<style>
	#page-loading{
		display: none;
	}
</style>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('文件销毁任务管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<% if(hasPermi('sd:docDestroyTask:edit')){ %>
					<a href="${ctx}/sd/docDestroyTask/form" class="btn btn-default btnTool" title="${text('新增文件销毁任务')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<% } %>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${docDestroyTask}" action="${ctx}/sd/docDestroyTask/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('任务名称')}：</label>
					<div class="control-inline">
						<#form:input path="taskName" maxlength="100" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('销毁日期')}：</label>
					<div class="control-inline">
						<#form:input path="destroyDate" readonly="true" maxlength="20" class="form-control laydate width-datetime"
							dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('销毁操作人')}：</label>
					<div class="control-inline width-120" >
						<#form:treeselect id="destroyUserCode" title="${text('用户选择')}"
							path="destroyUserCode" labelPath="destroyUserName"
							url="${ctx}/sys/office/treeData?isLoadUser=true" allowClear="true"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('监销人')}：</label>
					<div class="control-inline width-120" >
						<#form:treeselect id="destoyCheckUserCode" title="${text('用户选择')}"
							path="destoyCheckUserCode" labelPath="destoyCheckUserCodeName"
							url="${ctx}/sys/office/treeData?isLoadUser=true" allowClear="true"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm" >${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
	window.onload=function(){
		$("#page-loading").text("")
	}
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text("任务名称")}', name:'taskName', index:'a.task_name', width:150, align:"left", frozen:true, formatter: function(val, obj, row, act){
			return '<a href="${ctx}/sd/docDestroyTask/form?id='+row.id+'" class="btnList" data-title="${text("编辑文件销毁任务")}">'+(val||row.id)+'</a>';
		}},
		{header:'${text("销毁文件数")}', name:'fileCount', width:150, align:"center",formatter: function(val, obj, row, act){

				if("0"==row.fileCount){
				return 0;
				}else{
					return '<a href="javascript:;" data-click-binded="false" onclick="selectFiles(\''+row.id+'\')" >' +row.fileCount+"</a>";
			}


		}},

		{header:'${text("销毁日期")}', name:'destroyDate', index:'a.destroy_date', width:150, align:"center"},
		{header:'${text("销毁操作人")}', name:'destroyUser.userName', index:'u1.user_code', width:150, align:"center"},
		{header:'${text("监销人")}', name:'destoyCheckUser.userName', index:'u2.user_code', width:150, align:"center"},
		{header:'${text("操作")}', name:'actions', width:120, sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [];
			<% if(hasPermi('sd:docDestroyTask:edit')){ %>

				actions.push('<a href="${ctx}/sd/docDestroyTask/form?id='+row.id+'" class="btnList" title="${text("编辑文件销毁任务")}"><i class="fa fa-pencil"></i></a>&nbsp;');
				actions.push('<a href="${ctx}/sd/docDestroyTask/delete?id='+row.id+'" class="btnList" title="${text("删除文件销毁任务")}" data-confirm="${text("确认要删除该文件销毁任务吗？")}"><i class="fa fa-trash-o"></i></a>&nbsp;');
			<% } %>
				 if(row.destoyType=="0"){


					actions.push('<a href="javascript:;" onclick="addDestoyFile(\''+row.id+'\')" data-click-binded="false" class="btnList" title="${text("添加销毁文件")}"><i class="fa fa-fw icon-fire"></i></a>&nbsp;');
			}
			return actions.join('');
		}}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
	function  selectFiles(id) {
     js.layer.open({
		 type: 2,
		 area: [(js.layer.window.outerWidth - 350) + 'px', (js.layer.window.outerHeight - 200) + 'px'],
		 title: '${text("查看销毁文件")}',
		 resize: false,
		 scrollbar: true,
		 maxmin: true,
		 content: '${ctx}/sd/docDestoyRecord/getList?id='+id,
		 success: function (layero, index) {
		 },
		 btn: '<i class="fa fa-remove"></i> ${text("关闭")}',

	})

	}
	function  addDestoyFile(id) {
		js.layer.open({
			type: 2,
			area: [(js.layer.window.outerWidth - 350) + 'px', (js.layer.window.outerHeight - 200) + 'px'],
			title: '${text("选择文件")}',
			resize: false,
			scrollbar: true,
			maxmin: true,
			content: '${ctx}/sd/docDestroyTask/getInfor',
			success: function (layero, index) {
			},
			btn: ['<i class="fa fa-check"></i> ${text("销毁")}',
				'<i class="fa fa-remove"></i> ${text("关闭")}'],
			btn1: function (index, layero) {
				var win = layero.iframeWindow();
			//	alert("11")
				var lo=win.$('#dataGrid').dataGrid('getSelectRows');
				if (lo==""){
					js.layer.msg("请选择销毁文件",{icon:5})
					return false;

				}else{
				$.ajax({
					type: "POST",
					url: "${ctx}/sd/docDestroyTask/destoyFiles?ids="+lo,
					data:{"destroyId":id},
					success: function (data) {
						console.log(data)
                      if(data.result==Global.TRUE){
                          js.layer.msg("销毁成功",{icon:1})
						  js.layer.closeAll()
						  page()
                          return true;
					}else{
						  js.layer.msg("销毁失败",{icon:5})
						  page()
						  return false;
					}
					}
				})

			 }
				return false;

			}

		})
	}
</script>